package com.xyh.concurrency.example.atomic;

import java.util.concurrent.atomic.AtomicReference;

import com.xyh.concurrency.annoations.Recommend;

import lombok.extern.slf4j.Slf4j;

/**
 * 高并发原子性包
 * Atomic 包下面的所有类 cas
 */
@Slf4j
@Recommend
public class AtomicExample3 {
    /**
     * AtomicReference也是修改原子性的类
     */
    private static AtomicReference<Integer> integerAtomicReference = new AtomicReference<>(0);

    public static void main(String[] args) {
        integerAtomicReference.compareAndSet(0, 2);
        integerAtomicReference.compareAndSet(3, 5);
        integerAtomicReference.compareAndSet(2, 6);
        integerAtomicReference.compareAndSet(6, 3);
        log.info("integerAtomicReference{}", integerAtomicReference.get());
    }


}
